import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import '../css/Login.css';

const Login = () => {
  const [username, setUsername] = useState('');
  const [password, setPassword] = useState('');
  const navigate = useNavigate();

  const handleLogin = () => {
    if (username === 'admin' && password === '123456') {
      localStorage.setItem('user', username);
      navigate('/upload');
    } else {
      alert('用户名或密码错误！');
    }
  };

  return (
    <div className="login-container">
      <div className="login-card">
        <h2>登录系统</h2>
        <input
          type="text"
          placeholder="用户名"
          value={username}
          onChange={(e) => setUsername(e.target.value)}
        />
        <input
          type="password"
          placeholder="密码"
          value={password}
          onChange={(e) => setPassword(e.target.value)}
        />
        <button onClick={handleLogin}>登录</button>
      </div>
    </div>
  );
};

export default Login;
